package com.ideaaedi.springcloud.jd.commonds.enums;

import com.ideaaedi.springcloud.jd.commonds.entity.user.po.SysBackendUserPO;
import com.ideaaedi.springcloud.jd.commonds.entity.user.po.SysUserPO;
import com.ideaaedi.springcloud.jd.commonds.support.EnumDescriptor;
import com.ideaaedi.springcloud.jd.commonds.support.Locator;
import lombok.Getter;

import java.lang.reflect.Field;
import java.util.function.Supplier;

/**
 * po表相关state状态汇总
 *
 * @author <font size = "20" color = "#3CAA3C"><a href="https://gitee.com/JustryDeng">JustryDeng</a></font> <img
 * src="https://gitee.com/JustryDeng/shared-files/raw/master/JustryDeng/avatar.jpg" />
 * @since 1.0.0
 */
public interface POState {
    
    String FIELD_NAME = "state";
    
    /**
     * {@link SysBackendUserPO#getSubstate()}
     */
    @Getter
    enum SysUser implements EnumDescriptor, Locator<Field>, Supplier<Integer> {
        
        NORMAL(1, "正常"),
        ;
        
        /** 状态 */
        private final int state;
        
        /** 说明 */
        private final String desc;
    
        SysUser(int state, String desc) {
            this.state = state;
            this.desc = desc;
        }
    
        @Override
        public String obtainDescription() {
            return this.desc;
        }
    
        /**
         * 此枚举描述的字段
         */
        @Override
        public Field locate() {
            try {
                return SysUserPO.class.getDeclaredField(FIELD_NAME);
            } catch (NoSuchFieldException e) {
                throw new RuntimeException(e);
            }
        }
    
        @Override
        public Integer get() {
            return this.state;
        }
    }
}
